package cn.wd.user.controller;


import cn.wd.common.vo.R;
import cn.wd.user.domain.entity.ReportTable;
import cn.wd.user.page.PageResult;
import cn.wd.user.qo.ReportTableQueryObject;
import cn.wd.user.service.IReportTableService;
import cn.wd.user.vo.JsonResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/report")
public class ReportTableController {

    private final IReportTableService reportTableService;

    public ReportTableController(IReportTableService reportTableService) {
        this.reportTableService = reportTableService;
    }

    @RequestMapping("/list")
    public R<Page<ReportTable>> list(ReportTableQueryObject qo) {
        return R.OK(reportTableService.listReportTablePage(qo));
    }

    @RequestMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody ReportTable reportTable) {
        if (reportTable.getId() != null){
            reportTableService.updateById(reportTable);
        }else {
            reportTableService.save(reportTable);
        }
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    public JsonResult<?> delete(Long id) {
        if (id == null) {
            JsonResult.failed(401,"id 不能为空!");
        }
        reportTableService.removeById(id);
        return JsonResult.success();
    }
}
